var liveTable;
var roleid = document.getElementById("roleid").value;
if (roleid == "0") {
	document.getElementById("actions").style.visibility = "hidden";// 隐藏
}
function getliveList() {
	if (typeof liveTable !== 'undefined') {
		liveTable.fnPageChange('first');
		return;
	}
	var i = 1;
	liveTable = $("#liveList")
			.DataTable(
					{
						"sAjaxSource" : _path + "/live/queryByPage",
						"fnServerParams" : function(aoData) {
							aoData.push({
								"name" : "name",
								"value" : $("#name").val()
							}, {
								"name" : "status",
								"value" : $("#status").val()
							}, {
								"name" : "fromDate",
								"value" : $("#fromDate").val()
							}, {
								"name" : "toDate",
								"value" : $("#toDate").val()
							});
						},
						"sServerMethod" : "POST",
						"sAjaxDataProp" : "dataList",
						"fnCreatedRow" : function() {
							i++;
						},
						"fnPreDrawCallback" : function() {
							i = 1;
						},
						"aoColumns" : [
								{
									"sTitle" : "序号",
									"sWidth" : "2%",
									"mData" : function() {
										return i;
									}
								},
								{
									"sTitle" : "直播ID",
									"mData" : "id",
									"sWidth" : "6%"
								},
								{
									"sTitle" : "直播名称",
									"sWidth" : "10%",
									"mData" : function(data) {
										var name = '<a href="' + _path
												+ '/live/edit/' + data.id
												+ '" >' + data.name + '</a>';
										return name;
									}
								},
								{
									"sTitle" : "线路名",
									"mData" : "mainname",
									"sWidth" : "10%"
								},
								{
									"sTitle" : "线路状态",
									"mData" : "status",
									"sWidth" : "10%",
									"mRender" : function(data) {
										var status = '启动中';

										return status;
									}
								},
								{
									"sTitle" : "播放状态",
									"mData" : "status",
									"sWidth" : "10%",
									"mRender" : function(data) {
										var status = '';
										switch (data) {
										case '0':
											status = '播放片花';
											break;
										case '1':
											status = '播放直播';
											break;
										case '2':
											status = '播放回播';
											break;
										default:
											status = '未知';
											break;
										}
										return status;
									}
								},
								{
									"sTitle" : "发布时间",
									"mData" : "createTime",
									"sWidth" : "10%"
								},
								{
									"sTitle" : "操作员",
									"mData" : "user.username",
									"sWidth" : "10%"
								},
								{
									"sTitle" : "操作",
									"sWidth" : "10%",
									"mData" : function(data) {

										var status = '&#8197<select   cti="'
												+ data.name
												+ '"    id="select'
												+ data.id
												+ '" name="select" onchange='
												+ "advertising("
												+ data.id
												+ ",'"
												+ data.mainid
												+ "','"
												+ data.backid
												+ "',this)"
												+ ' style="height:21px" class="btn default btn-xs purple">'
												+ '<option value="" selected="selected">操作</option>'
											
												+ '<option value="0">开启自动留言</option>'
												+ '<option value="1">关闭自动留言</option>'
												+ '<option value="3">留言管理</option>'
											
												+ '</select>';
										
										// if (roleid == "0") {

										// }
										return status;
									}
								} ]
					});
}
function inquiry(id) {

	layer.confirm('这将删除所有相关信息！您确定要删除吗？', {
		btn : [ '确定', '取消' ]
	// 按钮
	}, function() {
		location.href = _path + "/live/del/" + id;
	}, function() {

	});
}
function evals(s) {
	return new Object();
};
// 下拉列表选项操作
function advertising(id, mainid, backid, em) {
	var name = $(em).attr("cti");
	var i = $("#select" + id).val(); // 获取选中的value的值
	var s = $("#select" + id).find("option:selected").text(); // 获取选中文本域的值
	if (i == '0' || i == '1' || i == '2') {
		$.ajax({
			type : "POST",
			url : _path + "/live/statusSwitch?id=" + id + "&isrobot=" + i,
			async : false,
			dataType : "json",
			error : function(request) {
				alert("连接错误！");
			},
			success : function(data) {
		
						layer.alert("状态切换成功");
					

			}

		});
	} else if (i == '3') {
		location.href = _path + "/chatRobot/list?liveId=" + id;
	} 
}


// 对当前页面进行刷新
function Refresh() {
	location.reload();
}
// 页面重定向跳转
function Refreshs(mainid, backid) {
	location.href = _path + "/relatedVideo/list/?mainid=" + mainid + "&backid="
			+ backid;
}
